package com.example.wendao.view.ui.fragment;


import android.os.Bundle;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Toast;

import com.example.wendao.App;
import com.example.wendao.R;
import com.example.wendao.viewmodel.UserViewModel;


/**
 * A simple {@link Fragment} subclass.
 */
public class PublishFragment extends Fragment {
public Button pu_goto_news;
public Button pu_goto_forum;
public UserViewModel userViewModel;

    public PublishFragment() {}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_publish, container, false);
        userViewModel = new ViewModelProvider(App.getInstance()).get(UserViewModel.class);
        pu_goto_news= view.findViewById(R.id.pu_goto_news);
        pu_goto_forum= view.findViewById(R.id.pu_goto_forum);

        pu_goto_news.setOnClickListener(view1 -> {
            if (!userViewModel.userLoggedIn())
            {
                Toast.makeText(getActivity(), "登录之后才可以发布新闻哦~", Toast.LENGTH_SHORT).show();
            }
            else
            {
                Navigation.findNavController(view).navigate(R.id.action_fragment_publish_to_publish_newsFragment);
            }
        });
        pu_goto_forum.setOnClickListener(view12 -> {
            if (!userViewModel.userLoggedIn())
            {
                Toast.makeText(getActivity(), "登录之后才可以发布论坛哦~", Toast.LENGTH_SHORT).show();
            }
            else
            {
                Navigation.findNavController(view).navigate(R.id.action_fragment_publish_to_publish_forumFragment);
            }
        });
        return view;

    }

}
